<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html>

<ui:composition template="../template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui">
    <h:outputStylesheet name="css/bootstrap.css" />
    <ui:define name="content"> 
        <h:outputScript target="head">  $ = jQuery;</h:outputScript><!--ESTA LINA ES NECESARIA PARA QUE FUNCIONE JQUERY-->
        <script type="text/javascript">
            $(document).ready(function() {
                $(".ui-messages").fadeOut(3000);
            });
        </script>
        <div class="col-md-6">
            <h4>Asignar &#211;rdenes de Trabajo en M&#224;quinas</h4>
            <h:form id="formu">
                <div class="btn-group" >
                    <h:commandButton value="Procesar" class="btn btn-default" action="#{asignaOrdenMaquina.procesar()}" />                             
                    <h:commandButton value="Imprimir" class="btn btn-default" action="#{asignaOrdenMaquina.imprimir()}" />                                 
                </div>

                <br/><p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" escape="false" /> <br/> 

                <h:panelGroup  rendered="#{asignaOrdenMaquina.listaOrdenes.size() > 0}" id="pnlnorows">    
                    <div class="panel panel-default">
                        <div class="table-responsive">
                            <p:dataTable id="tabla" var="p" value="#{asignaOrdenMaquina.listaOrdenes}" 
                                         paginator="true" rows="10"   paginatorPosition="bottom" 
                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                         rowsPerPageTemplate="5,10,15"   styleClass="table table-bordered table-striped table-condensed"
                                         style="font-size: 12px;" editable="true" editMode="cell" widgetVar="carsTable">  
                                <p:column headerText="N&#250;mero Orden"> 
                                    <h:outputText value="#{p.codigo}"/>
                                </p:column>
                                <p:column headerText="Cliente">    				
                                    <h:outputText value="#{p.descCliente}"/>   				
                                </p:column> 
                                <p:column headerText="Fecha">    				
                                    <h:outputText value="#{p.fechaRegistro}">
                                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                                    </h:outputText>   				
                                </p:column> 
                                <p:column headerText="Estado orden">    				
                                    <h:outputText value="#{p.estado}"/>
                                </p:column> 
                                <p:column headerText="M&#224;quina" style="width:25%">
                                    <p:commandLink oncomplete="asignarMaquina.show()" 
                                                   styleClass="btn btn-default"
                                                   update=":formu:asignarMaquina"
                                                   title="Asignar maquina"
                                                   action="#{asignaOrdenMaquina.mostrarPopupMaquinas(p)}"> 
                                        <h:graphicImage  library="pics" name="lista.png" width="15px;"/>
                                    </p:commandLink>
                                    <p:spacer width="10" height="10"/>
                                    <h:outputText value="#{p.codigoMaquinas}"/>
                                </p:column> 
                            </p:dataTable> 
                        </div>
                    </div>
                </h:panelGroup>
                <p:dialog id="asignarMaquina" widgetVar="asignarMaquina" modal="true" closeOnEscape="true" 
                          closable="true" width="800" header="Asignar maquina"
                          dynamic="true">
                    <div class="row">
                        <h:outputText value="Nro orden #{asignaOrdenMaquina.orden.codigo}"/>
                    </div>
                    <div class="row">
                        <h:panelGrid columns="3" cellpadding="5">
                            <h:outputLabel value="Maquinas:" />
                            <ui:fragment rendered="#{asignaOrdenMaquina.pintar}">
                                <p:selectCheckboxMenu id="menu" value="#{asignaOrdenMaquina.maquinaSelected}" 
                                                      filter="true" label="Maquinas"
                                                      filterMatchMode="startsWith" 
                                                      panelStyle="width:250px"
                                                      >
                                    <f:selectItems value="#{asignaOrdenMaquina.listaMaquinas}" var="m"
                                                   itemLabel="#{m.descripcion}"
                                                   itemValue="#{m.id}"/>
                                </p:selectCheckboxMenu>
                            </ui:fragment>
                            <ui:fragment rendered="#{!asignaOrdenMaquina.pintar}">
                                <p:selectOneMenu value="#{asignaOrdenMaquina.selectMaquina}" 
                                                 panelStyle="width:250px" 
                                                >
                                    <f:selectItems value="#{asignaOrdenMaquina.listaMaquinas}" var="m"
                                                   itemLabel="#{m.descripcion}"
                                                   itemValue="#{m.id}"/>
                                </p:selectOneMenu>
                            </ui:fragment>
                        </h:panelGrid>
                    </div>
                    <f:facet name="footer">
                        <p:commandLink ajax="true"
                                       process="asignarMaquina menu @this"
                                       update="formu"
                                       styleClass="btn btn-default"
                                       action="#{asignaOrdenMaquina.grabarMaquinas()}">
                            Grabar
                        </p:commandLink>
                    </f:facet>
                </p:dialog>

            </h:form>           
        </div>
    </ui:define>
</ui:composition>
